<?php defined('RUN_KATANA') or die('Restricted access'); ?>
<?php echo $commander->getListCommandsPanel('s', ''); ?>
<div class="menu_list list-items">
    <table style="clear:both;" id="menulist" class="item_list" cellspacing="0" cellpadding="0" border="0">
        <thead class="fields">
			<tr>
				<th class="first" style="text-align:center;">#</th>
				<th><?php echo ucfirst($txt->getWord('image')); ?></th>
				<th><?php echo ucfirst($txt->getWord('variation')); ?></th>
				<?php 
				if($shop->CurrentProduct->getAttributesVar())
				{
					$i=0;
					foreach($shop->CurrentProduct->getAttributesVar() as $att)
					{
						if(($att['effect_image'] > 0) && ($att['predefined'] > 0 && ($i == 0)))
						{ ?>
						 <th><?php echo ucfirst($att['title']); ?></th>
						 <?php
						 $i++;
						}
					}
				}
				?>
				<th><?php echo ucfirst($txt->getWord('default')); ?></th>
				<th class="last"><?php echo ucfirst($txt->getWord('delete')); ?></th>
			</tr>
			<tr class="items">
                <td class="first center"><img 	title="<?php echo ucfirst($txt->getWord('new')); ?>"
                                                class="icon command" 
                                                src="<?php echo SYSICONS_URL; ?>add_16.gif" 
                                                onclick="edit_form.submit();" /></td>
                <td><input class="medium" type="file" name="img_file[]" /></td>
                <td colspan="<?php echo $i+2; ?>">&nbsp;</td>
                <td class="last"></td>
            </tr>
		</thead>
		<tbody>
			<?php if($shop->CurrentProduct->getImages()): ?>
				<?php 
				$thsize = '';
				
				if(count($thumb['PRODUCT']) > 1)
				{ $thsize = $thumb['PRODUCT'][(count($thumb['PRODUCT'])-1)]['MAXW'].'_'; }
				foreach($shop->CurrentProduct->getImageObjects() as $primage): ?>
				<tr>
				<td class="center first">&nbsp;&nbsp;<?php echo $primage->getId(); ?>&nbsp;&nbsp;</td>
				<td>&nbsp;&nbsp;<?php echo '<a href="'.$primage->getLink().'" target="_blank"><img width="120" src="'.$primage->getLink(220, 220).'" /></a>'; ?>&nbsp;&nbsp;</td>
				<td valign="middle" class="center">&nbsp;&nbsp;
					<input type="hidden" name="img_id[]" value="<?php echo $primage->getId(); ?>" />
					<select class="small" name="img_variation_id[]" onchange="submit();">
						<option value="0" ><?php echo ucfirst($txt->getWord('all')); ?></option>
						<?php if($primage->getDefault() == 0): ?>
						<?php if($shop->CurrentProduct->Variations): ?>
						<?php foreach($shop->CurrentProduct->Variations as $var): ?>
						<option value="<?php echo $var->getId(); ?>" <?php echo getIsSelectedHTML($var->getId(), $primage->getVariationId()); ?>><?php echo $var->getVarTitle(); ?></option>
						<?php endforeach; ?>
						<?php endif; ?>
						<?php endif; ?>
					</select>
				</td>
					<?php 
					if($shop->CurrentProduct->getAttributesVar())
					{
						$i=0;
						foreach($shop->CurrentProduct->getAttributesVar() as $att)
						{
							if(($att['effect_image'] > 0) && ($att['predefined'] > 0) && ($i == 0))
							{
								?>
									<td>
										<select class="small" name="img_variation_value_id[]" onchange="submit();">
											<option value="0" ><?php echo ucfirst($txt->getWord('all')); ?></option>
											<?php 
											if($primage->getDefault() == 0)
											{
												foreach($shop->getProductAttribute($att['id'])->getValues() as $val)
												{ ?>
													<option value="<?php echo $val->getId(); ?>" <?php echo getIsSelectedHTML($val->getId(), $primage->getVariationValueId()); ?>><?php echo $val->getValue(); ?></option>
												   <?php
												}
											}
											?>
										</select>
									</td>
								<?
								$i++;
							}
						}
					}
					?>
				<td valign="middle" class="center"><?php echo $commander->getDefaultFields($primage, 'set_default_img'); ?></td>
				<td valign="middle" class="center"><img title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('image')); ?>" class="icon command cat_delete" src="<?php echo SYSICONS_URL; ?>delete_16.gif" onclick="deleteImageDialog(<?php echo $primage->getId(); ?>);" /></td>
				</tr>
				<?php endforeach; ?>
			<?php endif; ?>
		</tbody>
    </table>
    <input type="hidden" id="set_default_img" name="set_default_img" value="0" />
	<input type="hidden" id="del_image_id" name="del_img_id" value="0" />
</div>
<script type="text/javascript">
function deleteImageDialog(itemId)
{
	jQuery('#delete_image_dialog').dialog('open');
	jQuery('#delete_image_dialog').dialog({
		bgiframe: true,
		resizable: false,
		height:140,
		modal: true,
		overlay: 
		{
			backgroundColor: '#000',
			opacity: 0.5
		},
		buttons: 
		{
			'<?php echo ucfirst($txt->getWord('no')); ?>': function() 
			{
				jQuery(this).dialog('close');
			},
			'<?php echo ucfirst($txt->getWord('delete')).' '.$txt->getWord('image'); ?>': function() 
			{
				jQuery('#del_image_id').val(itemId);
				jQuery(this).dialog('close');
				jQuery('#edit_form').submit();
			}
		}
	});
}
</script>
<div id="delete_image_dialog" title="<?php echo ucfirst($txt->getWord('delete').' '.$txt->getWord('image')); ?>?" style="display:none; text-align:left;">
	<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 20px 0;"></span><?php echo ucfirst($txt->getWord('sure_you_want_to_delete').' '.$txt->getWord('image')); ?></p>
</div>